<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <script src="./js/vue.js"></script>
  </head>
  <!-- 
    v-for指令:
        1.用于展示列表数据
        2.语法:v-for="(item,index) in xxx" :key= "yyy"  这里的key最好用数据的唯一标识,虚拟dom比较，为了提高效率
        3.xxx可以是数组，对象，字符串，数字(指定遍历次数)   
   -->
  <body>
    <div id="root">
      <!-- 遍历数组 -->
      <h2>人员列表</h2>
      <ul>
        <!-- index 从0开始一次递增，key最好写上 -->
        <li v-for=" (person,index) in persons" :key="index">
          {{person.name}} - {{person.age}} -{{index}}
        </li>
      </ul>
      <!-- 遍历对象 -->
      <h2>汽车信息</h2>
      <ul>
        <li v-for="(key,val) in car" :key="key">{{key}} - {{val}}</li>
      </ul>
      <!-- 遍历字符串 -->
      <h2>遍历字符串</h2>
      <ul>
        <li v-for="(val,index) in str" :key="index">{{index}} - {{val}}</li>
      </ul>
    </div>

    <script>
      //创建Vue实例,得到 ViewModel
      var vm = new Vue({
        el: '#root',
        data: {
          persons: [
            { id: '01', name: '张三', age: 18 },
            { id: '02', name: '李四', age: 28 },
            { id: '03', name: '王五', age: 38 },
          ],
          car: {
            name: '奥迪A8',
            price: 700000,
            color: 'red',
          },
          str: 'hello',
        },

        methods: {},
        computed: {},
      })
    </script>
  </body>
</html>
